package com.example.cloudproviderorder80.service;

import com.example.api.entity.CommonResult;
import com.example.api.entity.Payment;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * 不想获取错误，那么就打开这里的//@Component
 * 注释PaymentFeignService的//@Component
 * 并在PaymentFeignService中使用@FeignClient(name = "CLOUD-PAYMENT-SERVICE", fallback = HystrixClientFallback.class)
 *
 * HystrixClientFallbackFactory是为了能够看到错误，现在的配置就是HystrixClientFallbackFactory方式
 *
 * 另外，官网现在还无法支持HystrixCommand，所以只能当作一个异常处理器，无法很好地使用HystrixCommand全功能
 * There is a limitation with the implementation of fallbacks in Feign and how Hystrix fallbacks work.
 * Fallbacks are currently not supported for methods that return com.netflix.hystrix.HystrixCommand and rx.Observable.
 *
 */
//@Component
class HystrixClientFallback implements PaymentFeignService {
    @Override
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id) {
        return new CommonResult<>(404, "找不到");
    }

    @Override
    public String feignTimeout() {
        return "feignTimeout666";
    }

    @Override
    public String feignException() {
        return "feignException555555";
    }
}
